package com.wys.read.service;

import cn.hutool.core.util.StrUtil;
import com.wys.read.dao.UserDao;
import com.wys.read.entity.User;
import com.wys.read.exception.FrameErrorCodeEnums;
import com.wys.read.exception.FrameRuntimeException;
import org.beetl.sql.core.query.LambdaQuery;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author wys
 * created in 23:24 2019/1/4
 */
@Service
public class UserService {

    @Autowired
    private UserDao userDao;

    // 通过名字获取账号
    public List<User> getUser(String name) {
        if (StrUtil.isBlank(name)) {
            throw new FrameRuntimeException(FrameErrorCodeEnums.BIND_ARGS_ERROR);
        }

        // 获取user的lambda表达式查询
        LambdaQuery<User> userLambdaQuery = userDao.createLambdaQuery();
        List<User> userList = userLambdaQuery.andEq(User::getAccountNumber, name).select();

        return userList;
    }

}
